# -*- coding: utf-8 -*-
import string
import math
import numpy as np
import matplotlib.pyplot as plt
filepath="/home/vancky/workshop_docs_softs/photometric_20130321_80_sx/"
band="R"
fpImageList=open(filepath+band+"image.lst",'r') # open image list file to read
fpCoorList=open(filepath+band+"Coor.lst",'w')#  open coord list to write
allLines=fpImageList.readlines()
Ans=np.zeros([len(allLines), 3])
x=0
for imageName in allLines:
	fp=open(imageName[:-5]+".coo.1.fit",'r') # read image coo.1,the output file of daofind
	print imageName[:-5]+".coo.1.fit",'r'
	fpCoorList.write(imageName.strip()+".photcoo\n")
	fpCoor=open(imageName.strip()+".photcoo",'w')  # open photcoo  to write
	print imageName.strip()+".photcoo"
	coorLine=fp.readline()
	starInfo1=[4,600,600]
	starInfo2=[4,440,901]
	while coorLine:
		#print coorLine
		if coorLine[0]!="#":
			outStr=coorLine.split()[0:3]
			outNum=[float(i) for i in outStr]
			if abs(outNum[2]+starInfo1[0])<1 and abs(outNum[0]-starInfo1[1])<100 and abs(outNum[1]-starInfo1[2])<100:
				print outNum
				Ans[x,:]=outNum[0:3]
				print "%f %f\n"%(outNum[0],outNum[1])
				fpCoor.write( "%f %f\n"%(outNum[0],outNum[1]) )
			if abs(outNum[2]+starInfo2[0])<1 and abs(outNum[0]-starInfo2[1])<100 and abs(outNum[1]-starInfo2[2])<100:
				print outNum
				Ans[x,:]=outNum[0:3]
				print "%f %f\n"%(outNum[0],outNum[1])
				fpCoor.write( "%f %f\n"%(outNum[0],outNum[1]) )
		coorLine=fp.readline()
	x=x+1
	fpCoor.close()
	fp.close()
fpImageList.close()
fpCoorList.close()
print "generate coord for phot success"





##### 

